﻿namespace Xms.Abp.Components;

public class EnabledColumn : Column<bool>
{
    protected override async Task OnInitializedAsync()
    {
        await base.OnInitializedAsync();
        ChildContent = build =>
        {
            build.OpenComponent<Switch>(0);
            build.AddAttribute(0, nameof(Switch.Value), Field);
            build.AddAttribute(1, nameof(Switch.CheckedChildren), "启用");
            build.AddAttribute(2, nameof(Switch.UnCheckedChildren), "禁用");
            build.AddAttribute(3, nameof(Switch.Disabled), Disabled?.Invoke() ?? false);
            build.AddAttribute(4, nameof(Switch.OnChange), OnChange);
            build.CloseComponent();
        };
    }

    [Parameter] public Func<bool> Disabled { get; set; }

    [Parameter] public EventCallback<bool> OnChange { get; set; }
}
